package com.fullmail.fragment;

import com.fullmail.MineCard;
import com.fullmail.R;
import com.fullmail.SettingActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

public class HomeMineFragment extends Fragment implements OnClickListener {
	private ImageView mIvHead;
	private ImageView mIvBgHead;
	private TextView mTvName;
	private TextView mTvHospital;
	private ImageView mRlQrCode;
	private RelativeLayout mRlRecord;
	private RelativeLayout mRlWorkday;
	private RelativeLayout mRlAbout;
	private RelativeLayout mRlSetting;
	private ScrollView mSvMine;
	private TextView mTvAddress;
	private RelativeLayout mRlMineDesc;
	private TextView mTvStatus;
	private TextView mTvEdit;
	private EditText mEtDescripe;
	private ImageView mIvAboutNext;
	private ImageView mIvGender;
private Context mContext;
private boolean isShowing;
private SharedPreferences sp;
private SharedPreferences.Editor editor;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		mContext=getActivity();
		View view = inflater.inflate(R.layout.fragment_home_mine, container, false);
		sp=mContext.getSharedPreferences("userInfo", Activity.MODE_PRIVATE);
		editor=sp.edit();
		initView(view);
		setListener();
		return view;
	}

	private void setListener() {
		// TODO Auto-generated method stub
		mRlRecord.setOnClickListener(this);
		mRlWorkday.setOnClickListener(this);
		mRlSetting.setOnClickListener(this);
		mRlAbout.setOnClickListener(this);
	}

	private void initView(View myView) {

		mIvHead = (ImageView) myView.findViewById(R.id.iv_mine_head);
		mIvBgHead = (ImageView) myView.findViewById(R.id.iv_mine_bg_head);
		mTvName = (TextView) myView.findViewById(R.id.tv_mine_nickname);
		mTvHospital = (TextView) myView.findViewById(R.id.tv_mine_hospital);
		mRlQrCode = (ImageView) myView.findViewById(R.id.iv_mine_qrcode);
		mRlRecord = (RelativeLayout) myView.findViewById(R.id.rl_mine_record);
		mRlWorkday = (RelativeLayout) myView.findViewById(R.id.rl_mine_workday);
		mRlAbout = (RelativeLayout) myView.findViewById(R.id.rl_mine_about);
		mRlSetting = (RelativeLayout) myView.findViewById(R.id.rl_mine_setting);
		mSvMine = (ScrollView) myView.findViewById(R.id.sv_home_mine_activity);
		mTvAddress = (TextView) myView.findViewById(R.id.tv_mine_address);
		mRlMineDesc = (RelativeLayout) myView.findViewById(R.id.rl_mine_descripe);
		mTvStatus = (TextView) myView.findViewById(R.id.tv_mine_status);

		mTvEdit = (TextView) myView.findViewById(R.id.tv_desc_edit);

		mEtDescripe = (EditText) myView.findViewById(R.id.et_rl_mine_descripe);
		mIvAboutNext = (ImageView) myView.findViewById(R.id.iv_mine_about_next);
		mIvGender = (ImageView) myView.findViewById(R.id.iv_home_mine_gender);
		mTvName.setText(sp.getString("username", "pounds"));
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v.getId() == R.id.rl_mine_record) {
			Intent receIntent= new Intent();
			receIntent.putExtra("selectItem", 0);
			receIntent.setClass(mContext, MineCard.class);
			mContext.startActivity(receIntent);
		}
		if (v.getId() == R.id.rl_mine_workday) {
			Intent seIntent= new Intent();
			seIntent.putExtra("selectItem", 1);
			seIntent.setClass(mContext, MineCard.class);
			mContext.startActivity(seIntent);
		}
		if (v.getId() == R.id.rl_mine_about) {
			if(isShowing){
				isShowing=false;
				mRlMineDesc.setVisibility(View.GONE);
			}else{
				isShowing=true;
				mRlMineDesc.setVisibility(View.VISIBLE);
			}
		}
		if (v.getId() == R.id.rl_mine_setting) {
			Intent setintent=new Intent();
			setintent.setClass(mContext, SettingActivity.class);
			mContext.startActivity(setintent);
		}
	}
}
